home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 108_01 / b.c < prev    next >
Text File  |  1985-11-13  |  6KB  |  195 lines

  1. /*    B.C
  2.  
  3.     Version 1.1    23-Aug-80
  4.  
  5.     This program prints out a sorted directory listing similar
  6.     to that that would be produced by a combination of STAT and
  7.     LIST. It is a modification of BIGDIR.C (written by Richard
  8.     Damon) designed for a Heath/Zenith H8 or H89/Z89. It is
  9.     configured for an H8/DEC VT100 in a 3-drive CP/M 1.43
  10.     environment, but it may be easily re-configured by changing
  11.     the commented definitions. For example, to configure it for
  12.     an H8/H19(ANSI) in a 2-drive CP/M 1.42 or 1.43:
  13.  
  14.        1.    #define    EXIT_STRING      "\n\033G\033<"
  15.        2.    #define    HEADER_IN_STRING  "\n\033[?2h\033p\033F"
  16.        3.    #define    HEADER_OUT_STRING "\n\033q"
  17.        4.    #define    NO_OF_DRIVES      2
  18.        5.    #define    VERTICAL_LINE      '\140'
  19.  
  20.     protocol:
  21.  
  22.         A>B    sorted directory of logged drive
  23.         A>B X    sorted directory of drive X
  24.         A>B *    sorted directory of all drives
  25.  
  26.     To configure it for non-Heath systems, the block which reads
  27.     the directory will have to be changed to read the correct
  28.     track with the correct skew. For standard CP/M, make the
  29.     following changes in addition to any re-configuration:
  30.     
  31.        1.    #define    CAPACITY      241    
  32.        2.    #define    DIRECTORY_TRACK      2
  33.        3.    #define    SECTORS_PER_TRACK 26
  34.        4.    #define    SKEW          6
  35.  
  36.        5.    replace the 'switch(sector)' block
  37.         with:
  38.             if(sector==1) sector=2;
  39.  
  40.     To configure it for 4 drives, make the following changes:
  41.  
  42.        1.    #define    NO_OF_DRIVES      4
  43.  
  44.        2.    int index; (was 'char')
  45.  
  46.        3.    in the setup and sort directory block:
  47.            1) change 'C' to 'D'
  48.            2) add the following immediately above:
  49.             else if(index<NO_OF_EXTENTS*4)
  50.                directory[index].unused[1]='C';
  51. */
  52.  
  53. #include <b:stdef.c>
  54. #include <b:system.c>
  55.  
  56. #define    ALL            '*'
  57. #define    CAPACITY        90
  58. #define    DIRECTORY_TRACK        3
  59. #define    ERASED            0xE5
  60. #define    EXIT_STRING        "\n\033(B"        /* exit_graphics    */    
  61. #define    FCB_LENGTH        32
  62. #define    HEADER_IN_STRING    "\n\033[1;7m\033(0"    /* reverse_video
  63.                            & enter_graphics */
  64. #define    HEADER_OUT_STRING   "\n\033[m"        /* normal_video        */
  65. #define    LENGTH_OF_DIRECTORY 16
  66. #define NO_OF_DRIVES        3            /* drives in system */
  67. #define    NO_OF_EXTENTS        64
  68. #define    SECTORS_PER_TRACK   20
  69. #define    SKEW            8
  70. #define    VERTICAL_LINE        '\170'        /* graphics vertical    
  71.                            line             */
  72.  
  73. #define    SETTRK            10
  74. #define    SETSEC            11
  75. #define    SETDMA            12
  76. #define    READ            13
  77.  
  78. main(argc,argv)
  79. int argc;
  80. char *argv[];
  81. {
  82.     struct fcb {
  83.        char entry_type;
  84.        char name[11];
  85.        char extent;
  86.        char unused[2];
  87.        char records;
  88.        char diskmap[16];
  89.     } directory[NO_OF_EXTENTS*NO_OF_DRIVES];
  90.  
  91.     char drive,entries,extents,index,logged_drive,loop_index;
  92.     char number_of_records,sector,used,wildcard;
  93.     int comp();
  94.  
  95. /*    process argument             */
  96.  
  97.     logged_drive=bdos(INTER_DISK,0);
  98.     if((wildcard=**++argv)==ALL) loop_index=0;
  99.     else {
  100.        (argc==1) ? drive=logged_drive : drive=wildcard-'A';
  101.        bdos(SELECT_DISK,drive); loop_index=NO_OF_DRIVES-1;
  102.        wildcard=RESET;
  103.        }
  104.  
  105. /*    read directory                  */
  106.  
  107.     entries=RESET;
  108.     do {
  109.        if(wildcard) bdos(SELECT_DISK,loop_index);
  110.        sector=1; bios(SETTRK,DIRECTORY_TRACK);
  111.        index=RESET;
  112.        do {
  113.           bios(SETSEC,sector); bios(SETDMA,&directory[entries++*4]);
  114.           bios(READ); sector+=SKEW;
  115.           if (sector>SECTORS_PER_TRACK) sector-=SECTORS_PER_TRACK;
  116.           switch(sector) {
  117.              case 7:  sector=4; break;
  118.              case 2:  sector=3; break;
  119.              case 1:  sector=2;
  120.              }
  121.           } while (++index<LENGTH_OF_DIRECTORY);
  122.        } while (++loop_index!=NO_OF_DRIVES);
  123.  
  124. /*    setup and sort directory        */
  125.  
  126.     if(wildcard) {
  127.        index=RESET; entries=NO_OF_EXTENTS*NO_OF_DRIVES;
  128.        do {
  129.           if(directory[index].entry_type!=ERASED) {    
  130.              if(index<NO_OF_EXTENTS) directory[index].unused[1]='A';
  131.              else if(index<NO_OF_EXTENTS*2)
  132.             directory[index].unused[1]='B';
  133.              else directory[index].unused[1]='C';
  134.              }
  135.           } while (++index<entries);
  136.        }
  137.     else entries=NO_OF_EXTENTS;
  138.     qsort(directory,entries,FCB_LENGTH,comp);
  139.  
  140. /*    print listing header              */
  141.  
  142.     index=RESET; printf(HEADER_IN_STRING);
  143.     do {
  144.        printf("FILENAME.EXT    NR  K");
  145.        if(index==2) {
  146.           if(wildcard) printf("  :");
  147.           break;
  148.           }
  149.        wildcard ? printf("  :   ") : printf("   ");
  150.     } while (++index<3);
  151.     printf(HEADER_OUT_STRING);
  152.  
  153. /*    print out sorted directory         */
  154.  
  155.     index=used=RESET;
  156.     do {
  157.        switch(index%3) {
  158.           case 0: putchar('\n'); break;
  159.           case 1:
  160.           case 2: printf("%c ",VERTICAL_LINE);
  161.           }
  162.          drive=directory[index].unused[1];
  163.        extents=directory[index].extent;
  164.        number_of_records=directory[index].records;
  165.        directory[index].unused[0]=EOS; loop_index=10;
  166.        do {
  167.           directory[index].name[loop_index+1]
  168.          =directory[index].name[loop_index];
  169.           } while (--loop_index>7);
  170.        directory[index].name[8]='.'; used+=(number_of_records+7)/8;
  171.        printf("%s",directory[index].name);
  172.        extents ? printf("+%d",extents) : printf("  ");
  173.        printf(" %3d %2d ",number_of_records,(number_of_records+7)/8);
  174.        if(wildcard) printf(" %c ",drive);
  175.        } while (!directory[++index].entry_type);
  176.  
  177. /*    print tail,select original drive    */
  178.  
  179.     printf(EXIT_STRING);
  180.     if (!wildcard) printf("\nfree: %dK\n",CAPACITY-used);
  181.     bdos(SELECT_DISK,logged_drive);
  182. }
  183.  
  184. /*    comparison function for 'qsort'        */
  185.  
  186. comp(x,y)
  187. char *x,*y;
  188. {
  189.     char index;
  190.     
  191.     for(index=1;(index||*x)&&*x!=ERASED&&*x==*y;
  192.        x++,y++,index=RESET);
  193.     if(*x>*y) return  1; if(*x<*y) return -1; return 0;
  194. }
  195.